<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" lang="zh_CN">
	<title>新建笔记</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<!-- 引入 Bootstrap -->
	<link rel="stylesheet" href="../css/bootstrap.min.css" />
	<!-- HTML5 Shim 和 Respond.js 用于让 IE8 支持 HTML5元素和媒体查询 -->
	<!-- 注意： 如果通过 file://  引入 Respond.js 文件，则该文件无法起效果 -->
	<!--[if lt IE 9]>
	<script type="text/javascript" src="../js/html5shiv.js" ></script>
	<script type="text/javascript" src="../js/respond.min.js" ></script>
	<![endif]-->
	<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
	<script type="text/javascript" src="../js/jquery.min.js"></script>

	<!-- include codemirror (codemirror.css, codemirror.js, xml.js, formatting.js)-->
	<link rel="stylesheet" href="../js/CodeMirror/lib/codemirror.css">
	<link rel="stylesheet" href="../js/CodeMirror/theme/eclipse.css">

	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/qiao.js"></script>
	<link rel="stylesheet" href="../css/summernote.css" />
	<script type="text/javascript" src="../js/summernote.min.js"></script>
	<script type="text/javascript" src="../js/summernote-zh-CN.js"></script>
	<script type="text/javascript" src="../js/code-prettify/prettify.js"></script>
	<link rel="stylesheet" href="../js/code-prettify/prettify.css" />
	<link rel="stylesheet" href="../js/select2/select2.min.css" />
	<script type="text/javascript" src="../js/select2/select2.min.js"></script>
	<script type="text/javascript" src="../js/jquery.scrollToTop.min.js"></script>
	<link rel="stylesheet" href="../css/style.css" />
	<!--AadminLTE基本资源-->
	<link rel="stylesheet" href="../css/font-awesome.min.css" />
</head>
<body>
<div class="container" id="app">
	<div class="row clearfix">
		<a href="#top" id="toTop"></a>
		<nav class="navbar navbar-inverse" role="navigation">
			<div class="navbar-header">
				<a class="navbar-brand" href="#">微雅视频</a>
			</div>
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
				<ul class="nav navbar-nav">
					<li>
						<a href="../index.html">首页</a>
					</li>
					<li class="active">
						<a href="#">新建笔记</a>
					</li>
					<li>
						<a href="../public/allType.html">全部分类</a>
					</li>
					<li>
						<a href="../public/search.html">高级搜索</a>
					</li>
				</ul>
				<form class="navbar-form navbar-left" target="_blank" role="search" action="../public/index.html">
					<div class="form-group">
						<input name="wd" type="text" class="form-control" placeholder="搜索笔记..." />
					</div> <button type="submit" class="btn btn-default">搜索</button>
				</form>
				<ul class="nav navbar-nav navbar-right">
					<li>
						<a href="javascript:nav_show();">网站导航</a>
					</li>
				</ul>
			</div>
		</nav>
	</div><!--The Header End-->
	<script>
        var nav_show = function () {
            qiao.bs.dialog({
                id : 'nav_index',
                url :'../public/nav.htm',
                head:false,
                foot:false,
                backdrop: true,
                big : true
            },function () {
                return true;
            });
        }
	</script>

	<div class="row clearfix" style="margin-bottom: -15px; margin-top: -15px;">
		<div class="box box-primary">
			<div class="box-header with-border">
				<div class="text-center">
					<h3 class="box-title pull-left">新建笔记</h3>
				</div>
				<div class="box-tools pull-right">
					<button type="button" class="btn btn-box-tool" data-widget="collapse">
						<i class="fa fa-minus"></i>
					</button>
				</div>
			</div>
			<!-- /.box-header -->
			<div class="box-body">
				<form class="form-inline text-center">
					<div class="form-group" style="margin-bottom: 20px;">
						<label>标题：</label>
					</div>
					<div class="form-group" style="margin-bottom: 20px;">
						<input type="text" size="50"  name="title"
							   class="form-control"
							   placeholder="请输入笔记标题..." />
					</div><br />

					<div class="form-group">
						<label>主分类：</label>
					</div>
					<div class="form-group">
						<select id="mainType" class="js-example-data-array form-control">
						</select>
					</div>
					<div class="form-group">
						<a href="javascript:addMType()">添加</a>
					</div>

					<div class="form-group">
						<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;子分类：</label>
					</div>
					<div class="form-group">
						<select id="childType" class="js-example-data-array form-control">
						</select>
					</div>
					<div class="form-group">
						<a href="javascript:addCHType();">添加</a>
					</div>

					<div class="form-group">
						<label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分享状态：</label>
					</div>
					<div class="form-group">
						<div class="btn-group-sm" id="share" data-toggle="buttons">
							<label class="btn btn-default active" style="height: 27px;">
								<input type="radio" name="share" class="toggle" value="0" checked="checked"> 分享
							</label>
							<label class="btn btn-default" style="height: 27px;">
								<input type="radio" name="share" class="toggle" value="1">不分享
							</label>
						</div>
					</div>
				</form>
			</div>

			<div class="" >
				<div class="summernote" id="summernote"></div>
			</div>
		</div>
		<div class="row text-center" style="margin-bottom: 20px;">
			<label class="btn btn-default" id="btn_view">预览</label>
			<label class="btn btn-default" id="btn_edit">编辑</label>
			<label class="btn btn-default" ng-click="saveData(1)" id="btn_save">保存</label>
		</div>
	</div>
	<!--富文本编辑器结束-->
	<div class="row">
		<div class="col-md-12 text-center footer">
		<span class="common">
	Copyright &copy;2020 微雅视频
	<a class="common" href="http://www.hncu.net" target="_blank">hncu.net</a>
	All Rights Reserved.
 </span>
		</div>
	</div>
	<!--底部声明结束-->
</div>
<script type="text/javascript" src="../js/CodeMirror/lib/codemirror.js"></script>
<script type="text/javascript" src="../js/CodeMirror/mode/javascript/javascript.js"></script>
<script type="text/javascript" src="../js/CodeMirror/mode/xml/xml.js"></script>
<script type="text/javascript" src="../js/CodeMirror/mode/htmlmixed/htmlmixed.js"></script>
<script type="text/javascript" src="../js/CodeMirror/mode/xml/xml.js"></script>
<script type="text/javascript" src="../js/CodeMirror/addon/fold/xml-fold.js"></script>
<script type="text/javascript" src="../js/CodeMirror/addon/edit/closetag.js"></script>
<script type="text/javascript" src="../js/CodeMirror/addon/edit/closebrackets.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script type="text/javascript" src="../js/verify.js"></script>
<script type="text/javascript">
    var mainData = [];
    var childData = [];
    //判读是否登录，没登录，重新加载
    var is_login = function (url,callback) {
        var url = url || '../isMaster';
        $.ajax({
            type:'post',
            url:url,
            success:function (result) {
                if(!result){
                    location.reload();
                    return false;
                }else {
                    if(typeof callback == "function"){
                        callback();
                    }
                    return true;
                }
            }
        });
    }
    $(function() {
        is_login();
        changSelect1(undefined,function () {
            changSelect2(mainData[0].id);
            $('#summernote').summernote(noteConf);
            //返回顶部代码
            $("#toTop").scrollToTop(800);
        });
    });

    //预览视图
    $("#btn_view").click(function() {
        var makrup = $('#summernote').summernote('code');
        makrup = makrup.replace(
            new RegExp('<script[^]*>[\\s\\S]*?</' + 'script>', 'gi'), '');
        $('#summernote').summernote('code',makrup);

        var summer = $('#summernote').summernote('code');
        var images = $(summer).find('img');
        var options = '';
        images.each(function () {
            var tmp = this.style.cssText;
            tmp = tmp.substring(tmp.indexOf(":")+1,tmp.indexOf("px"));
            if(!isEmpty(this.src) && !isEmpty(tmp)){
                options = options + this.src + '>'+$.trim(tmp)+"~";
            }
        });
        var options = '';
        console.log(getImages('#summernote',options));
        $('#summernote').summernote('destroy');
    });


    //编辑视图
    $("#btn_edit").click(function() {
        noteConf['height'] = 'auto';
        noteConf['focus'] = false;
        $('#summernote').summernote(noteConf);
    });

    $("#btn_save").click(function() {
        $("#btn_edit").click();
        var data = {
            title:$.trim($("input[name=title]").val()),
            mid : $('#mainType').select2("val"),
            chid: $('#childType').select2("val"),
            description : $.trim($('#summernote').summernote('code')),
            simpleDesc : $.trim(removeHTMLTag($('#summernote').summernote('code'))),
            share: $(":radio[name=share]:checked").val() || 0
        }
        if(!verifyStringLength(data.title,3,35)){
            qiao.bs.alert('标题长度范围3-35');
            return;
        }
        if(!verifyStringLength(data.simpleDesc,20,50000)){
            qiao.bs.alert('内容长度范围20-50000');
            return;
        }
        if(!verify(data.share,'int')){
            qiao.bs.alert('分享状态类型不匹配');
        }
        if(!verify(data.mid,'int')){
            qiao.bs.alert('主分类类型不匹配');
        }
        if(!verify(data.chid,'int')){
            qiao.bs.alert('子分类类型不匹配');
            return;
        }
        var images = '';
        images = getImages('#summernote',images);
        if(!isEmpty(images)){
            data.images = images;
        }
        $.ajax({
            type:"post",
            url:"addNote",
            data:data,
            success:function (result) {
                qiao.bs.confirm({
                    id:result.id,
                    title:'添加成功',
                    msg:'是否继续添加?',
                    okbtn:'继续添加',
                    qubtn:'结果预览',
                    keyboard:false,
                    close:false
                },function () {
                    $("input[name=title]").val('');
                    noteConf['height'] = '300';
                    noteConf['focus'] = true;
                    $('#summernote').summernote(noteConf);
                    $('#summernote').summernote('code', '');
                },function () {
                    window.location.href='next.html?id='+result.id;
                });
            }
        });
//                $('#summernote').summernote('pasteHTML', '<a>Hello</a>');
    });
</script>
</body>
</html>
